package com.cci.kangdao.controller;

import com.cci.kangdao.service.ServiceStationService;
import com.cci.kangdao.utilTool.ParameterTool;
import org.apache.commons.collections4.MapUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
 * @Description: 服务站相关信息业务
 * @Company: CTY
 * @author 米艳春
 * @date 2018-01-18
 * @version 1.0
 */
@Controller
public class ServiceStation {
	private Logger log = Logger.getLogger(this.getClass().getName());

	@Autowired
	private ServiceStationService serviceStationService;

	/**
	 * App获取字典表接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/getDictionaries.aspx")
	public ModelAndView userRegister(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceStationService.getDictionaries(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}

	/**
	 * App搜索服务站接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/searchServiceStation.aspx")
	public ModelAndView searchServiceStation(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceStationService.searchServiceStation(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}

	/**
	 * App根据服务站ID获取服务站信息
	 * @param map
	 * @return
	 */
	@RequestMapping("/getServiceStationById.aspx")
	public ModelAndView getServiceStationById(HttpServletRequest request,
											 HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceStationService.getServiceStationById(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
	
	/**
	 * App获取我的服务站接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/getMyServiceStation.aspx")
	public ModelAndView getMyServiceStation(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceStationService.getMyServiceStation(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * App修改服务站接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/updateMyServiceStation.aspx")
	public ModelAndView updateMyServiceStation(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			return serviceStationService.updateMyServiceStation(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * App上传服务站图片接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/uploadServiceStationImg.aspx")
	public ModelAndView uploadServiceStationImg(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceStationService.uploadServiceStationImg(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * App删除服务站图片接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/delServiceStationImg.aspx")
	public ModelAndView delServiceStationImg(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceStationService.delServiceStationImg(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * App获取服务站下属账号接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/getServiceStationUser.aspx")
	public ModelAndView getServiceStationUser(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("request", request);
			map.put("response", response);
			return serviceStationService.getServiceStationUser(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * App获取服务站下属账号接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/delServiceStationUser.aspx")
	public ModelAndView delServiceStationUser(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return serviceStationService.delServiceStationUser(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}

}
